from django.db import models
from django.contrib.auth.models import AbstractUser
# 用户表
class User(AbstractUser):
    major = models.CharField(max_length=10)
    mobile = models.CharField(max_length=11,unique=True, verbose_name='手机号', null=True)
    email = models.CharField(max_length=100,unique=True, verbose_name='邮箱', null=True)
    create_time = models.DateTimeField(auto_now=True,verbose_name='创建时间')
    update_date = models.DateTimeField(auto_now=True, verbose_name="更新时间")
    avatar = models.CharField(null=True, max_length=1024, verbose_name="用户头像")
    last_login = models.DateTimeField(null=True, blank=True)
    date_joined = models.DateTimeField(auto_now_add=True)
    answer_id = models.ForeignKey('Answer',on_delete=models.CASCADE,null=True)
    class Meta:
        db_table = 'tb_user'
        verbose_name = "用户"
        verbose_name_plural = verbose_name

# 班级表
class Classes(models.Model):
    STATE_CHOICES = (
        (0, "未毕业"),
        (1, "已毕业"),
    )
    class_id = models.AutoField(primary_key=True)
    class_name = models.CharField(max_length=20)
    group_id = models.ForeignKey('Group',on_delete=models.CASCADE,null=True)
    project = models.CharField(max_length=20,null=True)
    guidance = models.CharField(max_length=20,null=True)
    state = models.SmallIntegerField(choices=STATE_CHOICES, null=True,default=0, verbose_name="状态")

    class Meta:
        db_table = 'tb_class'
        verbose_name = "班级"
        verbose_name_plural = verbose_name


# 小组表
class Group(models.Model):
    group_id = models.AutoField(primary_key=True)
    group_name = models.CharField(max_length=20)
    student_id = models.ForeignKey('Student', on_delete=models.CASCADE,null=True)
    class_id = models.ForeignKey('Classes',on_delete=models.CASCADE,null=True)

    class Meta:
        db_table = 'tb_group'
        verbose_name = "小组"
        verbose_name_plural = verbose_name

# 学生表
class Student(models.Model):
    student_id = models.AutoField(primary_key=True)
    student_name = models.CharField(max_length=20)
    group_id = models.ForeignKey('Group',on_delete=models.CASCADE,null=True)

    class Meta:
        db_table = 'tb_student'
        verbose_name = "学生"
        verbose_name_plural = verbose_name
# PK表
class PK(models.Model):
    STATE_CHOICES = (
        (0, "班级PK"),
        (1, "组间PK"),
    )
    PK_name = models.CharField(max_length=20)
    start_date = models.DateTimeField(auto_now_add=True)
    end_date = models.DateTimeField(auto_now_add=True)
    class_id = models.ForeignKey('Classes',on_delete=models.CASCADE,null=True)
    state = models.SmallIntegerField(choices=STATE_CHOICES, null=True, default=0, verbose_name="状态")
    type = models.CharField(max_length=20,verbose_name='PK状态',null=True)
    win = models.CharField(max_length=20,verbose_name='获胜方',null=True)
    class Meta:
        db_table = 'tb_pk'
        verbose_name = "PK"
        verbose_name_plural = verbose_name

# 问题表
class Question(models.Model):
    STATE_CHOICES = (
        (0, "基础题"),
        (1, "高级题"),
    )
    question_name = models.CharField(max_length=20)
    ask = models.CharField(max_length=50,verbose_name='答案',null=True)
    update_time = models.DateTimeField(auto_now=True, verbose_name="最后修改时间")
    state = models.SmallIntegerField(choices=STATE_CHOICES, null=True, default=0, verbose_name="类型")

    class Meta:
        db_table = 'tb_question'
        verbose_name = "问题"
        verbose_name_plural = verbose_name

# 标签表
class Answer(models.Model):
    answer_name = models.CharField(max_length=20)

    class Meta:
        db_table = 'tb_answer'
        verbose_name = "标签"
        verbose_name_plural = verbose_name








